package com.ganlinux.pangoo.dao.othermodel;

import com.alibaba.fastjson.JSON;
import com.ganlinux.pangoo.entity.gaode.ReqAMapAddressSearchBean;
import com.ganlinux.pangoo.entity.gaode.RspAMapPlaceSearch;
import com.ganlinux.pangoo.entity.request.ReqAddressSearchList;
import com.ganlinux.pangoo.tools.BeanUtil;
import com.ganlinux.pangoo.tools.ConstantUtil;
import com.ganlinux.pangoo.tools.OkHttpUtil;
import com.jfinal.kit.HttpKit;

import java.io.IOException;

public class AddressSearchModel {
	/*public ReqBaidumapAddressSearch getAddressSearch(){
		Gson gson = new Gson();
		String rspString = null;
		ReqBaidumapAddressSearch addressSearch = null;
		try {
			addressSearch = new ReqBaidumapAddressSearch(URLEncoder.encode("餐馆", "UTF-8"), URLEncoder.encode("全国", "UTF-8"), "json", URLEncoder.encode("jSOARuabErrgYw0gzsqiBwIf716FPFtY", "UTF-8"), URLEncoder.encode("6D:00:00:5B:5A:92:E1:BA:1F:B4:F4:8E:8C:DD:72:CE:EC:6C:EE:EA;www.ganlinux.com.android", "UTF-8"));
		} catch (UnsupportedEncodingException e1) {
			// TODO Auto-generated catch block
			e1.printStackTrace();
		}
		
		try {
			rspString = OkHttpUtil.postFormbody(ConstantUtil.API_BASE_URL_BAIDUMAP, addressSearch);
		} catch (IOException e) {
			// TODO Auto-generated catch block
			e.printStackTrace();
		}
		RspBaiduPlaceSearch rspBaiduPlaceSearch = gson.fromJson(rspString, RspBaiduPlaceSearch.class);
		return addressSearch;
	}*/
	
	public RspAMapPlaceSearch getAMapAddressSearch(String keywords){
		String rspString = null;
		ReqAMapAddressSearchBean addressSearch = addressSearch = new ReqAMapAddressSearchBean(keywords, "", "全国", 1, 20, 1, "all", "5c9c7d73b92c9ab388cc23bbc34bbddb");
		/*try {
			rspString = OkHttpUtil.postFormbody(ConstantUtil.API_BASE_URL_AMAP, addressSearch);
		} catch (IOException e) {
			// TODO Auto-generated catch block
			e.printStackTrace();
		}
		RspAMapPlaceSearch rspAMapPlaceSearch = gson.fromJson(rspString, RspAMapPlaceSearch.class);*/


		rspString = HttpKit.get(ConstantUtil.API_BASE_URL_AMAP, BeanUtil.beanToMap(addressSearch));
		RspAMapPlaceSearch rspAMapPlaceSearch = JSON.parseObject(rspString, RspAMapPlaceSearch.class);
		return rspAMapPlaceSearch;
	}
}
